<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--<%@ page import="vo.com.jack.bookshop.PageVo" %>--%>
<%--<%@ page import="vo.com.jack.bookshop.BookVo" %>--%>
<%@ page import="com.jack.bookshop.dao.BookDao" %>
<%@ page import="com.jack.bookshop.vo.*" %>
<%@ page import="java.util.*" %>
<%@ page import="com.jack.bookshop.vo.BookVo" %>
<%@ page import="com.jack.bookshop.vo.PageVo" %>
<%--
  Created by IntelliJ IDEA.
  User: 炜杰
  Date: 2023/6/15
  Time: 10:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<%
    int c2 = Integer.parseInt(request.getParameter("c2"));
    int size = Integer.parseInt(request.getParameter("size"));
    int pagecode = Integer.parseInt(request.getParameter("page"));
    PageVo<BookVo> pageVo = new BookDao().getListByC2Id(c2, pagecode, size);
    pageContext.setAttribute("pageVo", pageVo);
    pageContext.setAttribute("page", pagecode);
    pageContext.setAttribute("c2", c2);
%>
<html>
<head>
    <title>Justin's Bookshop</title>
    <%@ include file="resource.jsp" %>
</head>
<body>
<%@ include file="header.jsp" %>
<div class="container" style="margin: 24px auto;">
    <div class="row">
        <div id="main" class="col-md-12">
            <p>
                <a href="index.jsp">Home</a>
                >>
                <a href="category.jsp">Category</a>
                >>
                <a href="category.jsp">${pageVo.list.get(0).c1_text}</a>
                >>
                <a href="">${pageVo.list.get(0).c2_text}</a>
            </p>
            <c:forEach var="element" items="${pageVo.list}" varStatus="status">
                <div class="card mb-3">
                    <div class="row g-0">
                        <div class="row">
                            <div class="col-md-4">
                                <img src="assets/images/books/${element.image_url}"/>
                            </div>
                            <div class="col-md-8">
                                <div class="card-body">
                                    <h5>${element.title}</h5>
                                    <p><strong>Score:</strong>
                                        <c:forEach begin="1" end="${element.score}" var="i">
                                            <i class="bi bi-star-fill"></i>
                                        </c:forEach>
                                    </p>
                                    <p><strong>Price:</strong>${element.price}</p>
                                    <p style="overflow: hidden;display: -webkit-box;-webkit-line-clamp: 7;-webkit-box-orient: vertical;">
                                        <strong>Description:</strong> ${element.description}
                                    </p>
                                    <a href="book-one.jsp?id=${element.id}" class="btn btn-primary">Read More</a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </c:forEach>
        </div>
    </div>

    <div style="display: flex;width: 100%;justify-content: center">
        <ul class="pagination">
            <li class="page-item <c:if test="${pageScope.page==1}">disabled</c:if>">
                <a class="page-link" href="book.jsp?c2=${pageScope.c2}&page=${pageScope.page-1}&size=2"> < Previous</a>
            </li>
            <li class="page-item <c:if test="${pageScope.page==1}">disabled</c:if>">
                <a class="page-link" href="book.jsp?c2=${pageScope.c2}&page=1&size=2">Page 1</a>
            </li>
            <li class="page-item active">
                <a class="page-link" href="#">Now:${pageScope.page}</a>
            </li>
            <li class="page-item <c:if test="${pageScope.page==pageScope.pageVo.total}">disabled</c:if>">
                <a class="page-link"
                   href="book.jsp?c2=${pageScope.c2}&page=${pageScope.pageVo.total}&size=2">End:${pageScope.pageVo.total}</a>
            </li>
            <li class="page-item <c:if test="${pageScope.page==pageScope.pageVo.total}">disabled</c:if>">
                <a class="page-link" href="book.jsp?c2=${pageScope.c2}&page=${pageScope.page+1}&size=2">Next > </a>
            </li>
        </ul>
    </div>
</div>
<%@ include file="footer.jsp" %>
</body>
</html>
